package logic

import (
	"context"
	"rpc/model/mysql"

	"rpc/internal/svc"
	"rpc/turn"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *turn.OrderListRequest) (*turn.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Order{}
	list, err := o.OrderList()
	if err != nil {
		return nil, err
	}
	var List []*turn.OrderItem
	for _, order := range list {
		List = append(List, &turn.OrderItem{
			OrderSn:     order.OrderSn,
			UserId:      order.UserId,
			GoodsId:     order.GoodsId,
			OrderAmount: float32(order.OrderAmount),
			OrderStatus: int64(order.OrderStatus),
			Payment:     int64(order.Payment),
		})
	}

	return &turn.OrderListResponse{OrderItem: List}, nil
}
